{include file='header'/}
<body class="pear-container">

<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab" lay-filter="test-hash">
            <ul class="layui-tab-title">
                <li class="layui-this">友情链接列表</li>
                <li><a href="{:url('linksGroup/index')}">友情链接分组</a></li>
            </ul>
        </div>

        <table id="links_table" lay-filter="links_table"></table>

    </div>
</div>

<script type="text/html" id="add_toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md"
            data-open="{:url('links/add')}"
            data-title="添加链接" data-reload-id="linksReload">
        <i class="layui-icon layui-icon-add-1"></i>
        新增链接
    </button>
</script>
<script type="text/html" id="barDemo">
    <button class="pear-btn pear-btn-primary pear-btn-xs" title="编辑"
            data-open="{:url('links/edit')}?id={{d.id}}"
            data-title="编辑" data-reload-id="linksReload">
        <i class="layui-icon layui-icon-edit"></i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-xs" title="删除"
            data-delete="{:url('links/delete')}?id={{d.id}}"
            data-title="您确定要删除吗？" data-reload="2">
        <i class="layui-icon layui-icon-delete"></i>
    </button>
</script>

<script id="logoTpl" type="text/html">
    {{#  if(d.logo !='' ){ }}
    <img src="{{d.logo}}" alt="" width="30" height="30">
    {{#  } }}

</script>
<script id="srcTpl" type="text/html">
    <a class="layui-btn layui-btn-xs" target="_blank" href="{{d.src}}">点击预览</a>
</script>

{include file='footer'/}
<script>
  layui.use(['table', 'jquery'], function () {
    var $ = layui.jquery;
    var table = layui.table;

    table.render({
      elem: '#links_table'
      , toolbar: '#add_toolbar'
      , defaultToolbar: [{
        layEvent: 'refresh',
        icon: 'layui-icon-refresh',
        title: '刷新'
      }, 'filter', 'exports']
      , method: 'get'
      , url: "{:url('links/index')}"
      , parseData: function (res) {
        return {
          "code": 0,
          "msg": res.msg,
          "count": res.count,
          "data": res.data
        };
      }
      , cellMinWidth: 100
      , cols: [[
        {field: 'id', title: 'ID', width: 60, align: 'center'}
        , {field: 'group_name', title: '分组名称', width: 150}
        , {field: 'name', title: '友链名称', minWidth: 120}
        , {field: 'logo', title: 'logo', templet: '#logoTpl',width:120}
        , {field: 'src', title: '友链地址', width: 120, templet: '#srcTpl'}
        , {field: 'sort', title: '排序', width: 50}
        , {field: 'update_time', title: '更新时间', width: 170}
        , {
          field: 'status', title: '状态', width: 100, align: 'center', templet: function (d) {
            if (d.status === 1) {
              return '<span class="layui-badge layui-bg-green">启用</span>';
            } else {
              return '<span class="layui-badge layui-bg-orange">禁用</span>';
            }
          }
        }
        , {fixed: 'right', title: '操作', toolbar: '#barDemo', align: 'center', width: 130}
      ]]
      , id: 'linksReload'
      , page: true
      , limit: 10
    });

    table.on('toolbar(links_table)', function (obj) {
      if (obj.event === 'refresh') {
        table.reload('linksReload');
      }
    });

  })
</script>
</body>
</html>
